home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Misc / SciCalc1.1 / Source / LcdText.m < prev    next >
Text File  |  1994-04-24  |  7KB  |  251 lines

  1. /***(LcdText.m)****************************************************************
  2. *H* LcdText implementation of Text Subclass                                 *
  3. ******************************************************************************/
  4.  
  5. #import <appkit/Pasteboard.h>
  6. #import <appkit/Font.h>
  7.  
  8. #import "LcdText.h"
  9. #import "Calculator.h"
  10.  
  11. void UTL_NxDumpEvent (NXEvent*, int, int, int);
  12.  
  13. @implementation LcdText
  14.  
  15. /******************************************************************************
  16. * FUNCTION: NoCharFilter                                                      *
  17. ******************************************************************************/
  18. unsigned short NoCharFilter
  19.  
  20.     (/* Arguments */
  21.     unsigned short  theChar,
  22.     int             flags,
  23.     unsigned short  charSet)
  24.  
  25. {
  26. return(theChar);
  27. }
  28.  
  29.  
  30.  
  31. /******************************************************************************
  32. * INSTANCE METHOD:- initFrame:                                                  *
  33. *   This  method  overrides  its  super  class  to  define  specific  initial *
  34. * attributes of a Text object.                                                   *
  35. ******************************************************************************/
  36. - initFrame
  37.  
  38.     /* Arguments */
  39.     :(NXRect *)frameRect
  40.  
  41. {   /* Local Variables */
  42.     NXRect sizeRect;
  43.  
  44. /* BEGIN-initFrame: */
  45. [super initFrame:frameRect];
  46.  
  47. /* Establish the font characteristics for this Text Object */
  48. [self setMonoFont:YES];
  49. [self setFont:[Font newFont:"Courier-Bold" size:14.0
  50.                     style:0 matrix:NX_FLIPPEDMATRIX]];
  51. [self setBackgroundGray:NX_WHITE];
  52. [self setOpaque:YES];
  53.  
  54. /* Set Text for resizing */
  55. [self notifyAncestorWhenFrameChanged: YES];
  56. [self setVertResizable:YES];
  57.  
  58. /* Set size restrictions appropriate for a scrolling Text Object */
  59. sizeRect = *frameRect;
  60. [self setMinSize:&sizeRect.size];
  61. sizeRect.size.height = 1.0e30;
  62. [self setMaxSize:&sizeRect.size];
  63.  
  64. [self setCharFilter:NoCharFilter];
  65.  
  66. /* Initial the text position of the beginning of the current line */
  67. IVstartOfCurLine = 0;
  68.  
  69. return(self);
  70. }/* END-initFrame: */
  71.  
  72.  
  73.  
  74. /******************************************************************************
  75. * INSTANCE METHOD:- keyDown:                                                  *
  76. *   This method captures any keystrokes  that  would have been interpreted by *
  77. * the LcdText Object and diverts  them  for  interpretation by the Calculator *
  78. * object.                                                                     *
  79. ******************************************************************************/
  80. - keyDown
  81.  
  82.     /* Arguments */
  83.     :(NXEvent *)event
  84.  
  85. {/* BEGIN-keyDown: */
  86. #ifdef DEBUG
  87. printf("LcdText-keyDown:");
  88. UTL_NxDumpEvent (event, 1, 1, 1);
  89. #endif
  90.  
  91. /* Give event to the Calculator Object */
  92. [Calculator KeyBoardEquivalent:event];
  93.  
  94. return(self);
  95. }/* END-keyDown: */
  96.  
  97.  
  98.  
  99. /******************************************************************************
  100. * INSTANCE METHOD:- paste:                                                *
  101. *   This method overides its super class to control what can be pasted to the *
  102. * LcdText object.  This  method  yanks the ASCII data from the Pasteboard and *
  103. * sends it to the Calculator Object for parsing. This restricts the text that *
  104. * can be pasted to the LcdTextObject.                                          *
  105. ******************************************************************************/
  106. - paste:sender
  107.  
  108. {   /* Local Variables */
  109.     id              pboard;
  110.     char         *pbData;
  111.     int              pbLength;
  112.     const NXAtom *pbTypes;
  113.  
  114. /* BEGIN-paste: */
  115. /* Query the Global Pasteboard Object for Id and Data Types */
  116. pboard  = [Pasteboard newName:NXGeneralPboard];
  117. pbTypes = [pboard types];
  118.  
  119. if ( [pboard readType:NXAsciiPboardType data:&pbData length:&pbLength] )
  120.     {/* Use the data here, keeping it for as long as necessary */
  121.     [Calculator PasteExpression:pbData Length:pbLength];
  122.     [pboard deallocatePasteboardData:pbData length:pbLength];
  123.     }
  124.  
  125. return(self);
  126. }/* END-paste: */
  127.  
  128.  
  129.  
  130. /******************************************************************************
  131. * INSTANCE METHOD:- newLine:                                              *
  132. *   This method places a new line at the end of the current line.             *
  133. ******************************************************************************/
  134. - newLine:sender
  135.  
  136. {   /* Local Variables */
  137.     int  endOfText;
  138.  
  139. /* BEGIN-newLine: */
  140. endOfText = [self textLength];
  141. [self setSel:endOfText :endOfText];
  142. [self replaceSel:"\n"];
  143. IVstartOfCurLine = endOfText+1;
  144. return(self);
  145. }/* END-newLine: */
  146.  
  147.  
  148.  
  149. /******************************************************************************
  150. * INSTANCE METHOD:- setCurrentLine:                                          *
  151. *   This method replaces the current line with the supplied text.             *
  152. ******************************************************************************/
  153. - setCurrentLine
  154.  
  155.     /* Arguments */
  156.     :(const char*)string    /* String to replace current line */
  157.  
  158. {   /* Local Variables */
  159.     int  endOfText;
  160.  
  161. /* BEGIN-setCurrentLine: */
  162. /* Turn off updates until finished mangling the text */
  163. [self setAutodisplay:NO];
  164.  
  165. /* Replace the text from the begining to the end of the current line */
  166. endOfText = [self textLength];
  167. [self setSel:IVstartOfCurLine :endOfText];
  168. [self scrollSelToVisible];
  169. [self replaceSel:string];
  170.  
  171. /* Restore updates and redisplay the Text object */
  172. [[self setAutodisplay:YES] display];
  173.  
  174. return(self);
  175. }/* END-setCurrentLine: */
  176.  
  177.  
  178.  
  179. /******************************************************************************
  180. * INSTANCE METHOD:- appendCurrentLine:                                          *
  181. *   This method appends the supplied text to the end of the current line.     *
  182. ******************************************************************************/
  183. - appendCurrentLine
  184.  
  185.     /* Arguments */
  186.     :(const char*)string    /*I* String to Append to current line */
  187.  
  188. {   /* Local Variables */
  189.     int  endOfText;
  190.  
  191. /* BEGIN-appendCurrentLine: */
  192. /* Turn off updates until finished mangling the text */
  193. [self setAutodisplay:NO];
  194.  
  195. /* Add new text at the end of the current line */ 
  196. endOfText = [self textLength];
  197. [self setSel:endOfText :endOfText];
  198. [self scrollSelToVisible];
  199. [self replaceSel:string];
  200.  
  201. /* Restore updates and redisplay the Text object */
  202. [[self setAutodisplay:YES] display];
  203.  
  204. return(self);
  205. }/* END-appendCurrentLine: */
  206.  
  207.  
  208.  
  209. /******************************************************************************
  210. * INSTANCE METHOD:- setTarget:Action:                                          *
  211. *   This method establishes an object to receive the action method specified. *
  212. ******************************************************************************/
  213. - setTarget
  214.  
  215.     /* Arguments */
  216.           :anObject
  217.     Action:(SEL)aSelector
  218.  
  219. {/* BEGIN-setTarget:Action: */
  220. IVactionId  = anObject;
  221. IVactionSel = aSelector;
  222. return(self);
  223. }/* END-setTarget:Action: */
  224.  
  225.  
  226. #if 0
  227. /******************************************************************************
  228. * INSTANCE METHOD:- textDidChange:                                            *
  229. ******************************************************************************/
  230. - textDidChange:sender
  231.  
  232. {/* BEGIN-textDidChange: */
  233. printf("LcdText:-textDidChange:\n");
  234. return(self);
  235. }/* END-textDidChange: */
  236.  
  237.  
  238.  
  239. /******************************************************************************
  240. * INSTANCE METHOD:- textWillChange:                                           *
  241. ******************************************************************************/
  242. - (BOOL)textWillChange:sender
  243.  
  244. {/* BEGIN-textWillChange: */
  245. printf("LcdText:-textWillChange:\n");
  246. return(YES);
  247. }/* END-textWillChange: */
  248. #endif
  249.  
  250. @end /* implementation LcdText */
  251.